home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 September (IDG) / Sep99.iso / Shareware World / Utilities / Text Processing / Alpha / Help / ElecCompletions Help < prev    next >
Encoding:
Text File  |  1999-02-26  |  16.3 KB  |  438 lines  |  [TEXT/ALFA]

  1. ## 
  2.  # ###################################################################
  3.  #  Vince's Additions - an extension package for Alpha
  4.  # 
  5.  #  FILE: "ElecCompletions Help"
  6.  #                                    created: 1/8/97 {2:24:21 pm} 
  7.  #                                last update: 26/2/1999 {8:17:54 pm} 
  8.  #  Author: Vince Darley
  9.  #  E-mail: <darley@fas.harvard.edu>
  10.  #    mail: Division of Engineering and Applied Sciences, Harvard University
  11.  #          Oxford Street, Cambridge MA 02138, USA
  12.  #     www: <http://www.fas.harvard.edu/~darley/>
  13.  #  
  14.  # Copyright (c) 1997-99  Vince Darley
  15.  # Some pieces pasted from Alpha-D mailing list responses.
  16.  # ###################################################################
  17.  ##
  18.  
  19.  
  20. The idea with electric completions is to save you key strokes. When you hit
  21. cmd-tab Alpha tries to expand what you have just typed to give the rest of
  22. what you want (the choice of cmd-tab can be adjusted in the 
  23. 'Config->Global->Special Keys' dialog).
  24.  
  25. If you want basic help/tutorial information, do the following: when 
  26. you're in a mode for which you want a tutorial on electric completions,
  27. select 'Completions Tutorial' from the 'Mode Prefs' menu.  Follow 
  28. the instructions there.
  29.  
  30. You can modify the following preferences using the 
  31. 'Config->Global->Flags->Electrics' menu item:
  32.  
  33.     • useElectricMenu --- use electric template menu 
  34.     • showElectricsInMenu --- show electric completions in menu 
  35.     • showElectricKeysInMenu --- show electric key bindings in menu
  36.     • modeSpecificElecTab --- use mode-specific electric tab 
  37.     • electricTab --- use electric tab 
  38.     • templateStopColor --- colour of template stops 
  39.     • listPickIfMultExpds --- similarly for expansions 
  40.     • ElectricFillers --- The format of the template stops:
  41.           0 = just use bullets
  42.           1 = use bullets but signal the name in the status window
  43.           2 = insert names into the window with the bullets
  44.           3 = insert names and highlight into the window with the bullets
  45.     • maxTemplateNesting--- level of nesting we allow before clearing 
  46.  
  47. The electric menu contains a 'Templates' sub-menu, which contains global 
  48. templates stored in the variable 'univ::MenuTemplates', and mode-specific
  49. templates stored in variables ${mode}Templates.  The format of these 
  50. variables is a list of names, which correspond to procedures when prepended 
  51. with 'file::'.  You can add new items by using the menu item.
  52.  
  53.           Templates
  54.  
  55. Many of the routines in Vince's Additions allow you to insert templates for 
  56. 'for' loops, '\begin...\end environments', file headers, function comments, 
  57. and even entire documents.  This section details the features of Vince's 
  58. Additions which allow you to do that.  Here's an example of a 'for' template
  59. in C++ mode (created just by typing 'for<cmd-Tab>'):
  60.  
  61.     for (•<init>;•<test>;•<increment>){
  62.         •<loop body>
  63.     }
  64.     •
  65.  
  66. Once a template has been inserted, it will often contain a number of 
  67. 'place-markers' or 'template-stops' at each of which you will most likely 
  68. wish to enter some text/code.  You can jump backwards and forwards amongst 
  69. these stops using a set of key bindings.  You have a choice between two 
  70. basic sets (you select using the 'Electric Bindings' dialog):
  71.  
  72.     Operation               Standard Bindings         Alternative Set
  73.  
  74.     "Next Stop Or Tab"       Tab                       ctrl-j      
  75.     "Complete"               cmd-Tab                   cmd-Tab     
  76.     "Expand"                 cmd-Space                 Tab 
  77.     "Prev Stop"              shift-Tab                 shift-ctrl-j        
  78.     "Real Tab"               opt-Tab                   opt-Tab
  79.     "nth Stop"               ctrl-Tab                  ctrl-opt-j          
  80.     "Clear All Stops"        shift-ctrl-Tab            shift-ctrl-opt-j            
  81.  
  82. Furthermore you can redefine any of these bindings using that same
  83. dialog.
  84.  
  85. You have a choice between four different formats for the visual appearance 
  86. of the template-stops.  They are usually signified by a bullet '•', but 
  87. more elaborate methods are supported.  These templates may be nested 
  88. without any extra effort on your part.  Most of this code is contained in 
  89. the file "betterTemplates.tcl", although all the bindings and initialisation 
  90. are in "elecBindings.tcl".
  91.  
  92. Look at the new 'electric' menu for a list of these bindings, together 
  93. with some other functions.
  94.  
  95. ================================================================================
  96.  
  97.           Completions
  98.  
  99. I've now written a unified collection of procedures to address command 
  100. completion, code indentation, electric-code generation, word completion and 
  101. related facilities (incorporating my old TeX-reference completion for 
  102. example). 
  103.  
  104. Here's a typical example from TeX mode, I type:
  105.  
  106.     for an explanation of this phenomenon,
  107.     please refer to Fig<cmd-Tab>
  108.     
  109. The <cmd-Tab> signifies that Vince's Additions should try to complete the 
  110. currently typed text.  In this case the completion is:
  111.  
  112.     for an explanation of this phenomenon,
  113.     please refer to Figure~\ref{fig-
  114.     
  115. If I hit <cmd-Tab> again, Vince's Additions tries to search for TeX 
  116. '\labels' which begin with 'fig-' to insert the first such label
  117. it finds into the text:
  118.  
  119.     for an explanation of this phenomenon,
  120.     please refer to Figure~\ref{fig-heat-vs-time}
  121.     
  122. If this is the wrong one, I can keep hitting <cmd-Tab> until I reach the 
  123. correct completion:
  124.  
  125.     for an explanation of this phenomenon,
  126.     please refer to Figure~\ref{fig-explanation}
  127.     
  128. Here's an example from C/C++ modes. I type 'for<cmd-Tab>' and get:
  129.  
  130.     for (;•;•){
  131.         •
  132.     }
  133.  
  134. This works at any current level of indentation, and the bullet marks '•' 
  135. are placemarkers.  You can just press 'Tab' (without 'cmd') to jump from 
  136. one to the next.
  137.  
  138. These facilities are activated as follows:
  139.  
  140. •    Tab --- plain - either 'indent' or 'next template mark'
  141.             cmd   - complete the current text.
  142.             opt   - insert a real tab.
  143.                         
  144. So, pressing Tab by default will _not_ necessarily insert a tab, rather it 
  145. will indent the current line of code to the correct indentation level to 
  146. match the code around it.  
  147.  
  148.             Types of completion
  149.  
  150.  
  151. Command-Tab has a number of different meanings, which will be explained 
  152. below.  Completions are listed in order of precedence.
  153.  
  154.               User completion: 
  155.  
  156. all entries defined in the array 'userCompletions' are checked and inserted 
  157. if appropriate.  This is useful to make 'vmd' turn into 'Vince Darley', or 
  158. 'www' into my home-page url, or ...
  159.     
  160. User completions are active in all modes, and take precedence over all 
  161. other completion types.
  162.  
  163.               Context sensitive completion: 
  164.  
  165. Context sensitive completions are mode dependent.  In some modes you 
  166. can tell relatively easily from the context whether a particular 
  167. 'word' is a variable or procedure name or...  If different completion
  168. procedures are useful for different types of word, then they are 
  169. checked next.  For instance, in Tcl mode, a word beginning with '$',
  170. or preceded by 'set' or 'global' is a variable name.  It should 
  171. therefore be completed preferentially as a variable, rather than
  172. being expanded as a command.  E.g. $str should normally not be
  173. expanded to '$string ...' since it's clearly not the command 'string' 
  174. that the user is trying to type.  
  175.  
  176.               Command completion: 
  177.  
  178. For instance: type 'str<cmd-tab>' and it is completed to 'string' (in Tcl 
  179. mode).  If there are multiple possibilities then the longest unique prefix 
  180. is inserted.
  181.     
  182. The available completions are mode dependent, and stored as a large string 
  183. in the variable ${mode}cmds.  They must be stored alphabetically, and
  184. be separated by whitespace.  THERE IS NO LONGER A NEED TO BEGIN AND
  185. END THE LIST WITH WHITESPACE.
  186.  
  187. Here is the default value for Tcl mode:
  188.  
  189.     set Tclcmds { append array catch close concat continue elseif error
  190.     for foreach format lindex lsearch lsort regexp regsub
  191.     rename return string switch while }
  192.  
  193.               Ensemble completion: 
  194.  
  195. type 'string co<cmd-Tab' and this is both completed to 'string compare' and 
  196. an electric template is inserted for the arguments of this two part 
  197. command.  Useful for any case in which the word before last is the command, 
  198. and the word just before is part of a refinement of that command, in any 
  199. situation for which a number of further arguments will be filled in.
  200.     
  201.               Electric code template generation: 
  202.  
  203. type 'for<cmd-tab>' and a complete template for code is generated (example 
  204. for C mode):
  205.     
  206.     for (;•;•){
  207.         •
  208.     }
  209.  
  210. You can move from one template mark '•' to the next with, plain 'Tab' - 
  211. I automatically sense whether a template insertion is in progress or
  212. not and interpret tab accordingly.
  213.  
  214. These are again mode dependent. Each is stored individually as an element 
  215. of the array ${mode}electrics, so, for instance the above electric code is 
  216. generated by:
  217.  
  218.     set Celectrics(for) " (••;••;••)\{\n\t••\n\}\n••"
  219.  
  220. Note how the bullets are double in the definition.  You can actually place 
  221. an explanatory bit of text between pairs of bullets.  This is then used as 
  222. a hint to the user:
  223.  
  224.     set Celectrics(for) " (•start•;•test•;•increment•)\{\n\t•body•\n\}\n••"
  225.  
  226.               Class name completion: 
  227.  
  228. In C++ mode, when entering a class definition, the class name occurs 
  229. multiple times.  To save entering all of these, this completion will
  230. fill them all in for you.  It works like this: type 'class<cmd-tab>'
  231.  
  232.     class •<object name> : public •<parent> {
  233.       public:
  234.         •<object name>(•<args>);
  235.         ~•<object name>(void);
  236.     
  237.     };
  238.     •
  239.  
  240. Now type the class name, say 'toaster', followed by <cmd-tab>.  This
  241. will result in:
  242.  
  243.     class toaster : public •<parent> {
  244.       public:
  245.         toaster(•<args>);
  246.         ~toaster(void);
  247.     
  248.     };
  249.     •
  250.  
  251. i.e. each occurrence of the electric stop 'object name' has been 
  252. filled in correctly.  This feature may be easily extended to more
  253. complex examples.
  254.  
  255.               TeX reference completion: 
  256.  
  257. type '\ref<cmd-Tab>' and the command is automatically completed with the 
  258. name of a nearby \label{}.  Repeated <cmd-Tab> keypresses will cycle 
  259. through all \label's.  Further, these commands chain together, so typing 
  260. '\eqr<cmd-Tab>' will complete the \eqref and continue to fill in a nearby 
  261. label!
  262.  
  263. These were explained above.  Note that the reference completions can be 
  264. instigated by command completion on, 'Fig' 'Chap' 'Eq.'  'Sec', ...  which 
  265. insert the standard label prefix 'fig:' 'chap:' 'eq:' 'sec:' as 
  266. appropriate.  If you complete with no prefix, then any label will match; if 
  267. you have a prefix then only those which match will be suggested.
  268.  
  269.               TeX citation completion.  
  270.  
  271. Type '\cite{Darley19<cmd-Tab>' and the command is completed with a matching 
  272. citation entry from one of your '.bib' database files.  If there are 
  273. multiple possibilities, then you are prompted with a list from which to 
  274. choose.  (Note: if you find the selection box a bit narrow, it is possible
  275. to edit Alpha using ResEdit to increase its size).  Depending upon the
  276. value of a TeX flag, the list can include the titles of each choice,
  277. making it more obvious to you which is correct.
  278.  
  279.               TeX environment completion: 
  280.  
  281. \begin{} \end{} pairs with synchronisation of the parameter, and template 
  282. generation of the body.
  283.  
  284. You can complete '\begin<cmd-Tab>' followed by 'equ<cmd-Tab>' to the
  285. following:
  286.  
  287.     \begin{equation}
  288.         •
  289.         \label{eq:•}
  290.     \end{equation}
  291.     •
  292.  
  293. You have a choice between the double-completion, as above, or just typing
  294. '\begin{equation}<cmd-Tab>' which will do the job in one go.
  295.  
  296. Similar things work for 'itemize' 'enumerate' etc.  Of particular use
  297. are the completions for 'figure' environments, from which you can enter
  298. ordinary figures, floating figures, and a large number of sub-figure 
  299. configurations (2 figures side-by-side, a block of 4,...).  For instance,
  300. a handful of key-presses will give you this:
  301.  
  302.     \begin{figure}
  303.         \centering
  304.         \subfigure[•“subfig caption”]{\label{fig:•}%
  305.             \includegraphics[width=\figstwo]{•“graphics file”}}\goodgaptwo
  306.         \subfigure[•“subfig caption”]{\label{fig:•}%
  307.             \includegraphics[width=\figstwo]{•“graphics file”}}\\
  308.         \subfigure[•“subfig caption”]{\label{fig:•}%
  309.             \includegraphics[width=\figstwo]{•“graphics file”}}\goodgaptwo
  310.         \subfigure[•“subfig caption”]{\label{fig:•}%
  311.             \includegraphics[width=\figstwo]{•“graphics file”}}%
  312.         \caption•“[short caption for t.o.f.]”{•“caption”}
  313.         \label{fig:•}
  314.     \end{figure}
  315.     •
  316.  
  317. For these to work, you must use the correct LaTeX packages (graphics, 
  318. floatingfigure or subfigure as appropriate, although the code will 
  319. automatically insert the correct 'usepackage' specifications for you if 
  320. desired), and you may need the following definitions in your LaTeX 
  321. preamble:
  322.  
  323.     \newlength{\goodspace}
  324.     \newlength{\goodspacethree}
  325.     \newlength{\goodspacefour}
  326.     \newlength{\figstwo}
  327.     \newlength{\figsthree}
  328.     \newlength{\figsfour}
  329.     
  330.     \setlength{\goodspace}{\subfigtopskip+\subfigbottomskip}
  331.     \setlength{\goodspacethree}{\goodspace}
  332.     \setlength{\goodspacefour}{\goodspace*\real{0.6}}
  333.     
  334.     \newcommand{\goodgap}{\hspace{\goodspace}}
  335.     \newcommand{\goodgaptwo}{\goodgap}
  336.     \newcommand{\goodgapthree}{\hspace{\goodspacethree}}
  337.     \newcommand{\goodgapfour}{\hspace{\goodspacefour}}
  338.     
  339.     \setlength{\figstwo}{(\linewidth-\goodspace)/2-1pt}
  340.     \setlength{\figsthree}{(\linewidth-\goodspace *2)/3-1pt}
  341.     \setlength{\figsfour}{(\linewidth-\goodspace *\real{1.8})/4-1pt}
  342.  
  343. These allow good alignment and spacing for most subfigure combinations
  344. without the need for manual intervention.  
  345.  
  346. Some environments can contain an arbitrary number of items.  In this case, 
  347. hitting 'shift-option-i' will add an item.  Here we turn this:
  348.  
  349.     \begin{description}
  350.         \item[First one] here's the description
  351.         
  352.         \item[•“name”] •“description”
  353.         
  354.     \end{description}
  355.     •
  356.  
  357. into:
  358.  
  359.     \begin{description}
  360.         \item[First one] here's the description
  361.         \item[•] •
  362.         
  363.         \item[•“name”] •“description”
  364.         
  365.     \end{description}
  366.     •
  367.  
  368. Similar entries work correctly for itemised, enumerated, aligned,... 
  369. environments.
  370.  
  371.               File-name completion:
  372.  
  373. Useful for Shel mode, this allows you to type a partial directory or 
  374. filename and hit cmd-Tab to have it extended as much as possible.
  375.  
  376.               Tcl Variable Completion:
  377.  
  378. Tcl variables are often referenced with '$var' or just 'var' or '${var}'.  
  379. You can complete between any of these types.  A local search for a match is 
  380. done and the closest match inserted.  Again you can cycle through other 
  381. matches with <cmd-Tab>
  382.  
  383.               Word Completion: 
  384.  
  385. if none of the above succeeded then the current word is completed to copy 
  386. nearby words (variable names) in the file.  Again, repeated presses will 
  387. cycle through other possibilities.
  388.  
  389. In any form of text in any mode, if no mode-specific completion matches, 
  390. then any local word can match, complete and be cycled through as usual.
  391.  
  392.             Template insertion
  393.  
  394. You'll notice in a lot of the above examples that bullets '•' are inserted 
  395. into the text.  In fact the user has a choice of four different levels of 
  396. interaction with the template insertion procedures.  You can change this 
  397. using the universal preferences dialog (in the config menu).  You can move
  398. from one insertion point to the next using the 'tab' key; move backwards 
  399. with 'shift-tab' and jump to any insertion point with 'ctrl-tab'.  If you 
  400. don't like these key bindings, an alternative set is available by a change 
  401. in the universal preferences.  You can also choose the colour of the
  402. inserted bullets/prompts.
  403.  
  404.             The Electric Menu
  405.  
  406. By default all items in the ${mode}electrics array are inserted into a new 
  407. menu.  This allows you to insert them, and get a feel for a small number 
  408. of the completions which exist.  Also at the bottom of the menu are items 
  409. for each of the standard key bindings these routines use, to help you to 
  410. remember them.
  411.  
  412.             Completion feedback
  413.  
  414. Help me to help you!
  415.  
  416. Completions for some common items just don't currently exist.  So if you 
  417. try to complete something and it doesn't work, why not write a completion 
  418. for it?  Once you have assembled a few, mail them to me (preferably 
  419. binhex'd, since bullets '•' don't travel well by ASCII mail).  I'd
  420. particularly like completions for other modes.
  421.  
  422.             Speed
  423.  
  424. Alpha has some limitations which means some aspects of Vince's Additions
  425. are a little bit slow (on low-end machines, at least).
  426.  
  427. Two things you can do to alleviate this: first, in modes for which Tab (or 
  428. ctrl-j under the alternative bindings) ALWAYS means to go the next template 
  429. stop and never means to indent the current line, define a new mode variable 
  430. 'tabNeverIndents' by adding the following line to your "prefs.tcl":
  431.   
  432.     newPref f tabNeverIndents 1 MODE
  433.  
  434. where 'MODE' is 'TeX', 'Java', 'HTML' or whatever.  You'll need to add one
  435. such line for each relevant mode.
  436.   
  437. ================================================================================
  438.